<template>
  <BaseForm
    labelWidth="105px"
    :fromIems="fromIems"
    :size="'medium'"
    ref="BaseForm"
    @submit="submit"
    @edit="edit"
  >
    <template #topbtn>
      <el-button icon="el-icon-setting"   type="primary" @click="confrim">发送机械命令</el-button>
    </template>
  </BaseForm>
</template>

<script>
import { Message } from "element-ui";
import { getDeviceInfo, sendjxcmd } from "@/api/device";
export default {
  data() {
    return {
      title: "",
      fromIems: [
        {
          valueType: "select",
          label: "风机模式",
          dataIndex: "fanMode",
          options: [
            {
              label: "标准",
              value: 0,
            },
            {
              label: "静音",
              value: 1,
            },
            {
              label: "关闭",
              value: 2,
            },
          ],
        },
        {
          valueType: "select",
          label: "X轴反向",
          dataIndex: "xReverse",
          options: [
            {
              label: "关",
              value: 0,
            },
            {
              label: "开",
              value: 1,
            },
          ],
        },
        {
          valueType: "select",
          label: "Y轴反向",
          dataIndex: "yReverse",
          options: [
            {
              label: "关",
              value: 0,
            },
            {
              label: "开",
              value: 1,
            },
          ],
        },
        {
          valueType: "select",
          label: "XY纠错开关",
          dataIndex: "xyCorrect",
          options: [
            {
              label: "关",
              value: 0,
            },
            {
              label: "开",
              value: 1,
            },
          ],
        },
        {
          valueType: "select",
          label: "XY轴速度",
          dataIndex: "xySpeed",
          options: [
            {
              label: "快速",
              value: 0,
            },
            {
              label: "正常",
              value: 1,
            },
            {
              label: "慢速",
              value: 2,
            },
          ],
        },
      ],
      isEdit: false,
    };
  },
  methods: {
    open(res) {
      const info = res.content;
      if (info.fanMoveInfo && JSON.parse(info.fanMoveInfo)) {
        this.$set(
          this.$refs.BaseForm.form,
          "fanMode",
          JSON.parse(info.fanMoveInfo).fanMode
        );
        this.$set(
          this.$refs.BaseForm.form,
          "xReverse",
          JSON.parse(info.fanMoveInfo).xReverse
        );
        this.$set(
          this.$refs.BaseForm.form,
          "yReverse",
          JSON.parse(info.fanMoveInfo).yReverse
        );
        this.$set(
          this.$refs.BaseForm.form,
          "xyCorrect",
          JSON.parse(info.fanMoveInfo).xyCorrect
        );
        this.$set(
          this.$refs.BaseForm.form,
          "xySpeed",
          JSON.parse(info.fanMoveInfo).xySpeed
        );
      }
      this.$nextTick(() => {
        if (res) {
          this.$set(this.$refs.BaseForm.form, "imei", res.content["imei"]);
        } else {
          this.$refs.BaseForm.form = {};
        }
      });
    },
    close() {
      this.$refs.baseDialog.close();
      this.$refs.BaseForm.rest();
    },
    confrim() {
      if (this.isEdit) {
        this.$refs.BaseForm.edit();
      } else {
        this.$refs.BaseForm.submit();
      }
    },
    async submit(data) {
      const res = await sendjxcmd(data);
      if (!res.status) {
        Message.success("发送机械命令成功");
      }
    },
    async edit(data) {
      const res = await sendjxcmd({
        imei: data.imei,
        imei: data.imei,
        fanMode: data.fanMode,
        xReverse: data.xReverse,
        yReverse: data.yReverse,
        xyCorrect: data.xyCorrect,
        xySpeed: data.xySpeed,
      });
      if (!res.status) {
        Message.success("发送机械命令成功");
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
